home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-15 | 4.4 KB | 159 lines | [TEXT/PJMM] |
- program Rotate;
-
- const
- BIT00 = $01;
- BIT01 = $02;
- BIT02 = $04;
- BIT03 = $08;
- BIT04 = $10;
- BIT05 = $20;
- BIT06 = $40;
- BIT07 = $80;
-
- var
- macBitMap: BitMap;
-
- procedure Rotate;
- var
- srcPtr, destPtr, destColPtr: Ptr;
- newBitmap: BitMap;
- bitchar, srcByte, srcH, srcV, srccols, srcrows, i: Integer;
-
- (* rotate boundary rectangle *)
- begin
- srcH := macBitMap.bounds.right - macBitMap.bounds.left;
- srcV := macBitMap.bounds.bottom - macBitMap.bounds.top;
- SetRect(newBitMap.bounds, macBitMap.bounds.left, macBitMap.bounds.top, macBitMap.bounds.left + srcV, macBitMap.bounds.top + srcH);
-
- (* allocate destination buffer *)
- newBitMap.rowBytes := BSR(srcV + 7, 3);
-
- newBitMap.baseAddr := NewPtrClear(newBitMap.rowBytes * srcH);
- newBitMap.bounds := newBitMap.bounds;
-
- (* set-up src to rotated destination scan *)
- srccols := macBitMap.rowBytes;
- srcrows := srcV;
- srcPtr := macBitMap.baseAddr;
- bitchar := BIT00;
- destColPtr := Ptr(Longint(newBitMap.baseAddr) + newBitMap.rowBytes - 1);
- destPtr := destColPtr;
-
- srcrows := srcrows - 1;
-
- (* scan src row and rotate into dest col *)
- while srcrows > 0 do
- begin
- for i := 0 to srccols - 1 do
- begin
- srcByte := srcPtr^;
- srcPtr := Ptr(Longint(srcPtr) + 1);
- if BAnd(srcByte, BIT07) <> 0 then
- destPtr^ := BitOr(destPtr^, bitchar);
- destPtr := Ptr(Longint(destPtr) + newBitMap.rowBytes);
- if BAnd(srcByte, BIT06) <> 0 then
- destPtr^ := BitOr(destPtr^, bitchar);
- destPtr := Ptr(Longint(destPtr) + newBitMap.rowBytes);
- if BAnd(srcByte, BIT05) <> 0 then
- destPtr^ := BitOr(destPtr^, bitchar);
- destPtr := Ptr(Longint(destPtr) + newBitMap.rowBytes);
- if BAnd(srcByte, BIT04) <> 0 then
- destPtr^ := BitOr(destPtr^, bitchar);
- destPtr := Ptr(Longint(destPtr) + newBitMap.rowBytes);
- if BAnd(srcByte, BIT03) <> 0 then
- destPtr^ := BitOr(destPtr^, bitchar);
- destPtr := Ptr(Longint(destPtr) + newBitMap.rowBytes);
- if BAnd(srcByte, BIT02) <> 0 then
- destPtr^ := BitOr(destPtr^, bitchar);
- destPtr := Ptr(Longint(destPtr) + newBitMap.rowBytes);
- if BAnd(srcByte, BIT01) <> 0 then
- destPtr^ := BitOr(destPtr^, bitchar);
- destPtr := Ptr(Longint(destPtr) + newBitMap.rowBytes);
- if BAnd(srcByte, BIT00) <> 0 then
- destPtr^ := BitOr(destPtr^, bitchar);
- destPtr := Ptr(Longint(destPtr) + newBitMap.rowBytes);
- end;
- if bitchar = BIT07 then
- begin
- bitchar := BIT00;
- destColPtr := Ptr(Longint(destColPtr) - 1);
- end
- else
- begin
- bitchar := BSL(bitchar, 1);
- end;
-
- destPtr := destColPtr;
-
- srcrows := srcrows - 1;
- end;
-
- (* remove src bitmap's baseAddr (portbits for offscreen port) *)
- DisposPtr(Ptr(macBitMap.baseAddr));
-
- (* store new src in object *)
- macBitMap := newBitMap;
- end;
-
- {main program}
-
- var
- mainWinPtr: WindowPtr;
- error: OSErr;
- windRect, ovalRect, myBounds: Rect;
- myRowBytes: Integer;
-
- (* There is NO reason to check whether ColorQD exists in this program!. *)
- begin
- (* Initialize all the needed managers. *)
- {$IFC UNDEFINED THINK_PASCAL}
- InitGraf(qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- {$ENDC}
- InitCursor;
-
- (* Define output window with an inset clip region. *)
- SetRect(windRect, 100, 100, 404, 404);
- {Make sure it fits on the screen}
- if windRect.bottom > screenBits.bounds.bottom then
- OffSetRect(windRect, 0, screenBits.bounds.bottom - windRect.bottom);
- mainWinPtr := NewWindow(nil, windRect, 'John', true, documentProc, WindowPtr(-1), false, 0);
- SetPort(mainWinPtr);
-
- SetRect(windRect, 0, 0, 304, 304);
- EraseRect(windRect);
- SetRect(ovalRect, 15, 15, 60, 120);
- PaintOval(ovalRect);
- MoveTo(10, 140);
- DrawString('Hi there.');
- MoveTo(0, 0);
- LineTo(303, 303);
- MoveTo(0, 303);
- LineTo(303, 0);
-
- (* rotate boundary rectangle *)
- myBounds := windRect;
- myRowBytes := BSR(myBounds.right - myBounds.left + 7, 3);
- {macBitMap := (BitMap * NewPtrClear(sizeof(BitMap));}
- macBitMap.baseAddr := Ptr(NewPtrClear(myRowBytes * (myBounds.bottom - myBounds.top)));
- macBitMap.bounds := myBounds;
- macBitMap.rowBytes := myRowBytes;
-
- CopyBits(mainWinPtr^.portBits, macBitMap, windRect, macBitMap.bounds, 0, nil);
-
- (* Wait until user clicks button. *)
- repeat
- until Button;
-
- (* Wait until user clicks button. *)
- repeat
- begin
- Rotate;
- CopyBits(macBitMap, mainWinPtr^.portBits, macBitMap.bounds, windRect, 0, nil);
- end
- until Button;
- end.